package com.xym.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.xym.web.Service.IndexService;

@Controller
public class IndexController {

	@Autowired
	private IndexService indexService;

	/**
	 * 首页跳转
	 * 
	 * @return
	 */
	@RequestMapping(value = "index", method = RequestMethod.GET)
	public ModelAndView index() {
		ModelAndView modelAndView = new ModelAndView("index");

		// 查询广告，后台查询
		try {
			//int i=1/0;
			//查询大广告
			String indexAd1 = indexService.queryIndexAD1();
			modelAndView.addObject("indexAD1", indexAd1);
			//查询小广告
			String indexRAD =indexService.queryIndexRAD();
			modelAndView.addObject("indexRAD", indexRAD);
			//查询轮播广告 CrollAD
			String CrollAD =indexService.queryIndexCrollAD();
			modelAndView.addObject("CrollAD", CrollAD);
			return modelAndView;
		} catch (Exception e) {
			e.printStackTrace();
		}

		// 异常返回大广告
		String indexAd111 = "{'src': 'http://image.xym.com/images/2017/12/30/2017123009011077706149.jpg',"
				+ "'width': 670,"
				+ "'height': 240,"
				+ "'alt': '',"
				+ "'href': 'http://sale.jd.com/act/e0FMkuDhJz35CNt.html?cpdad=1DLSUE',"
				+ "'srcB': 'http://image.xym.com/images/2017/12/30/2017123009011077706149.jpg',"
				+ "'widthB': 550," + "'heightB': 240}";
		// 手动拼接测试
		String indexAd1 = "[" + indexAd111 + "," + indexAd111 + ","
				+ indexAd111 + "," + indexAd111 + "," + indexAd111 + ","
				+ indexAd111 + "]";
		modelAndView.addObject("indexAD1", indexAd1);
		return modelAndView;
	}
}
